package com.qinghe.plant.config;

import java.lang.reflect.Field;
import java.util.Properties;

import com.qinghe.plant.util.ManageTool;

public class PropertiesReader {
   
	public PropertiesReader()
	{}
	
	public <T> T ReadProperties(String file,Class<T> type)
	{
		try
		{
			Properties p = new Properties();
			p.load(this.getClass().getClassLoader().getResourceAsStream(String.format("%s.properties", file)));
			
			T object=type.newInstance();
			Field[] fields=object.getClass().getDeclaredFields();
			for (int i = 0; i < fields.length; i++) {
				if(p.containsKey(fields[i].getName()))
				{
					ManageTool.SetValue(fields[i], object, p.getProperty(fields[i].getName()));
				}
			}
			return object;
		}
		catch(Exception e)
		{
			ManageTool.Log("数据库配置文件读取错误："+e.getMessage());
			return null;
		}
	
	}
}
